import * as qs from "qs";
import * as Config from "@/config";
import { post,get } from "@/api/httpRequest";

/**
 * 图谱生成相关API
 * ！！！http请求需要调用 httpRequest下方法 其中封装了登录状态检测逻辑
 */

const BASE_URI = Config.HTTP_SERVER + "/kgbuilder";

export function createKgAPI(data, success, error, final) {
  console.log(data)
  let configs = {
    headers: { "Content-Type": "application/x-www-form-urlencoded" }
  };
  post(BASE_URI + "/newKg", qs.stringify(data), success, error, final, configs);
}

/**
 * 上传xlsx文件，获取知识图谱绘图数据
 * @param data
 * @param success
 * @param error
 * @returns {*}
 */
export function uploadFileAPI(data, success, error, final) {
  let configs = { headers: { "Content-Type": "multipart/form-data" } };
  post(BASE_URI + "/uploadFile",data,success,error,final,configs);
}

export function getKgsAPI(success, error) {
  get(BASE_URI + "/getKgs", success, error);
}

export function getListAPI(success, error) {
  get(BASE_URI + "/getDataList", success, error, () => {});
}

export function loadDataAPI(kgId, success, error, final) {
  let config = {
    headers: { "content-type": "application/x-www-form-urlencoded" }
  };
  let data = qs.stringify({ kgId: kgId });
  post(BASE_URI + "/loadData", data, success, error, final, config);
}

export function deleteKgAPI(kgId, success, error) {
  let config = { headers: { "content-type": "application/x-www-form-urlencoded" }};
  let data = qs.stringify({ kgId: kgId });
  post(BASE_URI + "/deleteKg", data, success, error, () => {}, config);
}
